﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FXC.SL.Interface;
using Telerik.Windows.Controls;
using FXC.SL.CS.Util;
using FXC.SL.CS.ChartUtil;

namespace FXC.SL.UserControls.Window
{
    public partial class ChartProperty : RadWindow
    {
        private IChart _sourceChart;
        public ChartProperty(IChart sourceChart)
        {
            InitializeComponent();
            _sourceChart = sourceChart;
            InitializeColors();
        }

        private void InitializeColors()
        {
            ChartTheme ct = _sourceChart.FXVChartTheme;
            BindTheme(ct);
            //TODO: Intialize sample chart
        }

        private void btnReset_Click(object sender, RoutedEventArgs e)
        {
            // set to default theme
            BindTheme(null);
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            ChartTheme newCT = new ChartTheme();
            newCT.BackgroundColor.Color = rcpBackground.SelectedColor;
            newCT.ForegroundColor.Color = rcpForeground.SelectedColor;
            newCT.GridColor.Color = rcpGrid.SelectedColor;
            newCT.BarStrokeColor.Color = rcpBarStroke.SelectedColor;
            newCT.BarFillColor.Color = rcpBarFill.SelectedColor;
            newCT.VolumeColor.Color = rcpVolume.SelectedColor;
            newCT.LineTypeColor.Color = rcpLineType.SelectedColor;
            _sourceChart.FXVChartTheme = newCT;
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void BindTheme(ChartTheme ct)
        {
            if (ct == null)
                ct = new ChartTheme();
            rcpBackground.SelectedColor = ct.BackgroundColor.Color;
            rcpForeground.SelectedColor = ct.ForegroundColor.Color;
            rcpGrid.SelectedColor = ct.GridColor.Color;
            rcpBarStroke.SelectedColor = ct.BarStrokeColor.Color;
            rcpBarFill.SelectedColor = ct.BarFillColor.Color;
            rcpVolume.SelectedColor = ct.VolumeColor.Color;
            rcpLineType.SelectedColor = ct.LineTypeColor.Color;
        }
    }
}
